<extend name="Public/base"/>
<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>

    <form action="" method="post" class="form-horizontal">
        <!--  名称  -->
        <div class="form-item">
            <label class="item-label">名称</label>
            <div class="controls">
                <input type="text" class="text input-large" name="name" placeholder="请输入名称" value="{$info.name}">
            </div>
        </div>

        <!--  所属学科  -->
        <div class="form-item">
            <label class="item-label">所属学科</label>
            <div class="controls">
                <select name="sid" class="subject">
                    <option value="0">请选择学科</option>
                    <volist name="subject_list" id="vo">
                        <option value="{$vo.id}" <if condition="$vo['id'] == $info['sid']">selected</if>>{$vo.name}</option>
                    </volist>
                </select>
            </div>
        </div>

        <!--  章节 - 知识点  -->
        <div class="form-item">
            <label class="item-label">章节 - 知识点</label>
            <div class="controls">
                <select name="one_chapter_id" class="one_chapter">
                    <option value="0">请选择章节</option>
                </select>
                <select name="two_chapter_id" class="two_chapter">
                    <option value="0">请选择知识点</option>
                </select>
            </div>
        </div>

        <!--  年份  -->
        <div class="form-item">
            <label class="item-label">年份</label>
            <div class="controls">
                <select name="year">
                    <volist name="year_list" id="vo">
                        <option value="{$vo}" <if condition="$vo == $info['year']">selected</if>>{$vo}</option>
                    </volist>
                </select>
            </div>
        </div>

        <!--  单选题数量  -->
        <div class="form-item">
            <label class="item-label">单选题数量</label>
            <div class="controls">
                <input type="number" class="text input-large single_count" oninput="doScore()" name="single_count" placeholder="请输入单选题数量" value="{$info.single_count}" readonly>
            </div>
        </div>

        <!--  单选题单题分数  -->
        <div class="form-item">
            <label class="item-label">单选题单题分数</label>
            <div class="controls">
                <input type="number" class="text input-large single_score" oninput="doScore()" name="single_score" placeholder="请输入单选题单题分数" value="{$info.single_score}">
            </div>
        </div>

        <!--  多选题数量  -->
        <div class="form-item">
            <label class="item-label">多选题数量</label>
            <div class="controls">
                <input type="number" class="text input-large check_count" oninput="doScore()" name="check_count" placeholder="请输入多选题数量" value="{$info.check_count}" readonly>
            </div>
        </div>

        <!--  多选题单题分数  -->
        <div class="form-item">
            <label class="item-label">多选题单题分数</label>
            <div class="controls">
                <input type="number" class="text input-large check_score" oninput="doScore()" name="check_score" placeholder="请输入多选题单题分数" value="{$info.check_score}">
            </div>
        </div>

        <!--  分数  -->
        <div class="form-item">
            <label class="item-label">分数</label>
            <div class="controls">
                <input type="number" class="text input-large score" name="score" placeholder="总分数自动计算" value="{$info.score}" readonly>
            </div>
        </div>

        <!--  标签  -->
        <div class="form-item">
            <label class="item-label">标签<span class="check-tips">（多个用逗号分隔）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="tags" value="{$info.tags}" placeholder="请输入标签">
            </div>
        </div>

        <!--  类型  -->
        <div class="form-item">
            <label class="item-label">类型</label>
            <div class="controls">
                <select name="type" class="type">
                    <option value="1" <if condition="$info['type'] == 1">selected</if>>练习册</option>
                    <option value="2" <if condition="$info['type'] == 2">selected</if>>试卷</option>
                </select>
            </div>
        </div>

        <!--  所属模块  -->
        <div class="form-item">
            <label class="item-label">所属模块</label>
            <div class="controls">
                <select name="style" class="style_list">
                    <option value="1">章节练习</option>
                </select>
            </div>
        </div>

        <!--  是否热门  -->
        <div class="form-item">
            <label class="item-label">是否热门</label>
            <div class="controls">
                <label><input type="radio" name="is_hot" value="0" <if condition="$info['is_hot'] == 0">checked</if>> 否</label>
                <label><input type="radio" name="is_hot" value="1" <if condition="$info['is_hot'] == 1">checked</if>> 是</label>
            </div>
        </div>

        <!--  排序  -->
        <div class="form-item">
            <label class="item-label">排序</label>
            <div class="controls">
                <input type="number" class="text input-large" name="desc" placeholder="请输入排序" value="{$info.sort}">
            </div>
        </div>

        <!--  介绍  -->
        <div class="form-item">
            <label class="item-label">介绍</label>
            <div class="controls">
                <textarea name="desc" cols="54" rows="10">{$info.desc}</textarea>
            </div>
        </div>

        <input type="hidden" value="{:I('id')}" name="id" />
        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        $(function (){
            var subject_list = {$subject_list_json};
            var sid = "{$info.sid}";
            var one_chapter_id = "{$info.one_chapter_id}";
            var two_chapter_id = "{$info.two_chapter_id}";

            if(subject_list.length > 0){
                var option = "<option value='0'>请选择章节</option>";
                var two_option = "<option value='0'>请选择知识点</option>";
                //渲染学科下拉列表
                for(var i = 0; i < subject_list.length; i++){
                    if(subject_list[i].id == sid){
                        chapter_list = subject_list[i].chapter_list;
                        //渲染章节下拉列表
                        for (var j = 0; j < subject_list[i].chapter_list.length; j++) {
                            var obj = subject_list[i].chapter_list[j];
                            var one_selected = '';
                            if(one_chapter_id == obj.id) one_selected = 'selected';
                            option += "<option value='"+ obj.id +"' "+ one_selected +">"+ obj.name +"</option>";

                            if(one_chapter_id == obj.id){
                                var two_chapter_list = obj.son_list;
                                console.log(two_chapter_list)
                                if(two_chapter_list.length > 0){
                                    //渲染知识点下拉列表
                                    for (var k = 0; k < two_chapter_list.length; k++) {
                                        var two_obj = two_chapter_list[k];
                                        var two_selected = '';
                                        if(two_chapter_id == two_obj.id) two_selected = 'selected';
                                        two_option += "<option value='"+ two_obj.id +"' "+ two_selected +">"+ two_obj.name +"</option>";
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                $('.one_chapter').html(option);
                $('.two_chapter').html(two_option)
            }

            var type = "{$info.type}";
            var style = "{$info.style}";
            if(type == 2){
                //试卷
                var two = '';
                var three = '';
                var four = '';

                if(style == 2){
                    two = 'selected';
                }else if(style == 3){
                    three = 'selected';
                }else if(style == 4){
                    four = 'selected';
                }
                var option = '<option value="2" '+ two +'>巩固考试</option><option value="3" '+ three +'>真题模考</option><option value="4" '+ four +'>精品试卷</option>';
                $('.style_list').html(option);
            }
        })

        $('.subject').change(function (){
            var subject_list = {$subject_list_json};
            var sid = $(this).val();

            if(subject_list.length > 0){
                var option = "<option value='0'>请选择章节</option>";
                for(var i = 0; i < subject_list.length; i++){
                    if(subject_list[i].id == sid){
                        chapter_list = subject_list[i].chapter_list;
                        for (var j = 0; j < subject_list[i].chapter_list.length; j++) {
                            var obj = subject_list[i].chapter_list[j];
                            option += "<option value='"+ obj.id +"'>"+ obj.name +"</option>";
                        }
                        break;
                    }
                }
                $('.one_chapter').html(option);
                $('.two_chapter').html('<option value="0">请选择知识点</option>')
            }
        })

        var chapter_list = [];
        $('.one_chapter').change(function (){
            var one_chapter_id = $(this).val();
            if(chapter_list.length){
                var option = "<option value='0'>请选择知识点</option>";
                for(var i = 0; i < chapter_list.length; i++){
                    if(chapter_list[i].id == one_chapter_id){
                        for (var j = 0; j < chapter_list[i].son_list.length; j++) {
                            var obj = chapter_list[i].son_list[j];
                            option += "<option value='"+ obj.id +"'>"+ obj.name +"</option>";
                        }
                        break;
                    }
                }
                $('.two_chapter').html(option);
            }
        })

        $('.type').change(function (){
            var type = $(this).val();

            if(type == 1){
                var option = '<option value="1">章节练习</option>';
            }else{
                var option = '<option value="2">巩固考试</option><option value="3">真题模考</option><option value="4">精品试卷</option>';
            }
            $('.style_list').html(option);
        })

        function doScore()
        {
            var single_count = $('.single_count').val();
            var single_score = $('.single_score').val();
            var check_count = $('.check_count').val();
            var check_score = $('.check_score').val();

            var score = parseFloat(single_count * single_score) + parseFloat(check_count * check_score);
            $('.score').val(score);
        }

        //导航高亮
        highlight_subnav('{:U("Manage/practiceList")}');
    </script>
</block>